﻿using System.Drawing;
using System;
using Microsoft.DirectX.Direct3D;

namespace Space_Conquest
{
    class Text
    {

        private static System.Drawing.Font[] winFonts;
        private static Microsoft.DirectX.Direct3D.Font[] dxFonts;

        /// <summary>
        /// Static text constructor, create an array of text objects, one object for each text size
        /// </summary>
        static Text()
        {

            winFonts = new System.Drawing.Font[73];
            dxFonts = new Microsoft.DirectX.Direct3D.Font[73];

            for (int i = 8; i < 73; ++i)
            {

                winFonts[i] = new System.Drawing.Font("Arial", (float)i, FontStyle.Regular);
                dxFonts[i] = new Microsoft.DirectX.Direct3D.Font(Globals.device, winFonts[i]);

            }

        }

        /// <summary>
        /// Renders Text on Screen
        /// </summary>
        /// <param name="TextToRender"></param>
        /// <param name="color"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void Render(string textToRender, int size, Color color, int x, int y)
        {

            if (size < 8 || size > 72)
            {
                throw new Exception("Invalid font size to render with, choose a size between 8 and 72");
            }

            try
            {
                dxFonts[size].DrawText(null, textToRender, new Point(x, y), color);
            }
            catch
            {

                #if DEBUG
                Helpers.LogEvent("Space_Conquest.Text.Render() (Framework/Text.cs)", "Failed to render text");
                #endif

            }

        }

        /// <summary>
        /// Renders text with advanced formating (alignment options)
        /// </summary>
        /// <param name="textToRender"></param>
        /// <param name="size"></param>
        /// <param name="color"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="format"></param>
        public static void Render(string textToRender, int size, Color color, int x, int y, int width, int height, DrawTextFormat format)
        {

            if (size < 8 || size > 72)
            {
                throw new Exception("Invalid font size to render with, choose a size between 8 and 72");
            }

            try
            {
                dxFonts[size].DrawText(null, textToRender, new Rectangle(x, y, width, height),format, color);
            }
            catch
            {

                #if DEBUG
                Helpers.LogEvent("Space_Conquest.Text.Render() (Framework/Text.cs)", "Failed to render text");
                #endif

            }

        }

        /// <summary>
        /// Renders Text on Screen (default size is 14 pt)
        /// </summary>
        /// <param name="TextToRender"></param>
        /// <param name="color"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void Render(string textToRender, Color color, int x, int y)
        {

            Render(textToRender, 14, color, x, y);
        
        }



    }
}
